import axios from 'axios' //加载数据请求
import route from '../../router'
import {
  Loading,
  Message
} from 'element-ui';
axios.defaults.headers.post['Accept'] = 'application/json;charset=utf-8';
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// axios.defaults.headers.common['token'] = 'Bearer ' + uni.getStorageSync('TOKEN')
let loadinginstace;
// 拦截器

axios.interceptors.request.use(function (config) {
  loadinginstace = Loading.service({
    fullscreen: true
  });
  return config;
});
axios.interceptors.response.use(function (response) {
  // 响应成功关闭loading
  loadinginstace.close();
  return response;
});

export default {
  axios,
  post(url, data) {
    return new Promise((resolve, reject) => {
      axios({
        method: 'post',
        url: url,
        data: data,
        // headers: {
          // 'TOKEN': "Bearer " + uni.getStorage('TOKEN')
        // }
      }).then(res => {
		console.log(res)
      }).catch(error => {
		console.log(error)
      })
    })
  },
  get(url, params) {
    return new Promise((resolve, reject) => {
      axios({
        method: 'get',
        url: url,
        params:params,
        headers: {
          'X-Requested-With': 'XMLHttpRequest',
          'Authorization': 'Bearer ' + uni.getStorageSync('TOKEN')
        }
      }).then(res => {
        console.log(res)
      }).catch(error => {
		console.log(error)
      })
    })
  }
  // post(url, data) {
  //   return new Promise((resolve, reject) => {
  //     axios({
  //       method: 'post',
  //       url: url,
  //       data: data,
  //       headers: {
  //         // 'Content-Type': 'application/json',
  //         // 'TOKEN': sessionStorage.getItem('TOKEN')
  //       }
  //     }).then(res => {
  //       console.log(res)
  //     }).catch(error => {
  //       console.log(error)
  //     })
  //   })
  // }

}


